package com.javaee.response;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * <li>用重定向的方式处理登录以后的页面跳转
 * <li>完成最简单的模拟用户登录检测
 * 
 * @author fhzheng
 *
 */
public class LoginServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// response.setContentType("text/html;charset=utf-8");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		System.out.println(username);
		System.out.println(password);
		// 写死一对用户名和密码，模拟用户登录检查，要注意业务控制
		if (("admin").equals(username) && ("123456").equals(password)) {
			// 重定向是客户端再发请求，所以/代表的是网站，而不是网站下的应用程序项目，这里要用相对路径
			response.sendRedirect("./welcome.html");
		} else {
			response.sendRedirect("./login.html");
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}
